﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.XHRS
{
    class Class1
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            switch (ppa.Age)
            {
                case 18:
                case 19:
                case 20:
                case 21:
                    da.Value = ppa.Amount * 0.2;
                    da.Description = "大学教育金";
                    break;
                case 22:
                    da.Value = ppa.Amount * 0.6;
                    da.Description = "深造金";
                    break;
                case 25:
                    da.Value = ppa.Amount * 0.8;
                    da.Description = "立业金";
                    break;
                case 28:
                    da.Value = ppa.Amount * 0.8;
                    da.Description = "婚嫁金";
                    break;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {


            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                if (ppa.Age < 18)
                {
                    da.Value = ppa.TotalFee;
                }
                else
                {
                    da.Value = ppa.Amount * 3;
                }
                ppa.IsCurrentFinish = true;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {


            if (ppa.SchemePeriodActing.HolderStates.Contains("身故") || ppa.SchemePeriodActing.HolderStates.Contains("全残") && ppa.Period>0)
            {
                ppa.Fee = 0;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");

                ppa.Amount += ppa.PolicyActing.PeriodActings[ppa.Period - 1].Amount * f;
            }

            if ((ppa.Period + 1) % 2 == 0 && ppa.Age <66)
            {
                da.Value = ppa.Amount * 0.08;
            }

            if (ppa.Age >= 66)
            {
                da.Value = ppa.Amount * 0.08;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.Age == 66)
            {
                da.Value = ppa.Amount;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.SchemePeriodActing.InsurantStates.Contains("全残") && ppa.Period>0)
            {
                ppa.Fee = 0;
            }
                
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("疾病身故"))
            {
                if (ppa.Period == 0)
                {
                    da.Value = ppa.Amount * 0.1 + ppa.TotalFee;
                }
                else if(ppa.Age <66)
                {
                    da.Value = ppa.Amount * 3;
                }
                else if (ppa.Age >= 66)
                {
                    da.Value = ppa.Amount * 1.5;
                }

                ppa.SchemePeriodActing.InsurantStates.Add("身故");
                ppa.IsCurrentFinish = true;
            }else if (ppa.SchemePeriodActing.InsurantStates.Contains("疾病身故"))
            {

                if (ppa.Age < 66)
                {
                    da.Value = ppa.Amount * 3;
                }
                else if (ppa.Age >= 66)
                {
                    da.Value = ppa.Amount * 1.5;
                }

                ppa.SchemePeriodActing.InsurantStates.Add("身故");
                ppa.IsCurrentFinish = true;
            }


        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.Period == 4)
            {
                da.Value = ppa.Amount * 0.2;
            }else if((ppa.Period + 1) % 5 == 0)
            {
                IPolicyPeriodActing pppa=ppa.PolicyActing.PeriodActings[ppa.Period-5];
                IDutyActing pda = pppa.DutyActings.FirstOrDefault(p => p.Duty.Name == "生存保险金");

                if (pda != null)
                {
                    da.Value = pda.Value * 1.05;
                }

            }

            if ((ppa.Period + 1) % 5 == 0)
            {
                da.Value = (ppa.Amount * 0.2) + ((ppa.Period+1)/5 -1)*ppa.Amount * 0.05;
            }
            

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故") )
            {
                if (ppa.GetDutyTotalValue("高残保险金") <=double.Epsilon)
                {
                    da.Value = ppa.Amount * 2;
                }
                ppa.IsCurrentFinish = true;
                
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.SchemePeriodActing.InsurantStates.Contains("高残") && ppa.GetDutyTotalValue("高残保险金")<=double.Epsilon)
            {
                da.Value = ppa.Amount * 2;
                if (ppa.Period > 0)
                {
                    ppa.Fee = 0;
                }
            }

        }
    }
}
